package com.cjl.jdk8;

public class TryWithResource {

    public static void main(String[] args) {
        System.out.println("TryWithResource.main");

        try (MyCloseable closeable = new MyCloseable("closeable1");
             MyCloseable closeable2 = new MyCloseable("closeable2")){
            closeable.test();
            closeable2.test();
            System.out.println("TryWithResource.main after try");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("TryWithResource.main finally");
        }
    }

    private static class MyCloseable implements AutoCloseable{
        private String name;

        public MyCloseable(String name) {
            this.name = name;
        }

        @Override
        public void close() throws Exception {
            System.out.println(name+"   MyCloseable.close");
        }

        public void test(){

        }
    }
}

